<template>
  <div>
    <el-popover placement="left" width="200" trigger="hover" v-model:show="showPopover">
      <template #reference>
        <div slot="reference" class="highLight"><i class="iconfont icon-wenzigaoliang"></i>
          <p class="word">高亮</p></div>
      </template>
      <div class="controls">
        <input type="color" v-model="highlightColor" @input="updateHighlightColor" />
        <el-button type="primary" @click="highlightSelection">高亮选定文本</el-button>
        <el-button type="danger" @click="removeHighlights">移除所有高亮</el-button>
        <el-button type="warning" @click="removeSelectedHighlight">移除所选文字高亮</el-button>
      </div>
    </el-popover>
<!--    <div class="bodyText">-->
<!--      <template v-for="(word, index) in words" :key="index"><span-->
<!--          :style="{ backgroundColor: highlightedWords.includes(index) ? highlightColor : '' }"-->
<!--          @mouseup="storeSelectionRange(index)">{{ word }}</span></template>-->
<!--    </div>-->
  </div>
</template>
<script setup>
import { ref } from 'vue';

const highlightColor = ref("#ffff00");
const showPopover = ref(false);
const emit = defineEmits('updateHighlightColor', 'highlightSelection', 'removeHighlights', 'removeSelectedHighlight');

const highlightSelection = () => {
  console.log("highlightSelection is called highLight")
  emit('highlightSelection');
};

const removeHighlights = () => {
  emit('removeHighlights');
};

const removeSelectedHighlight = () => {
  emit('removeSelectedHighlight');
};

const updateHighlightColor = () => {
  emit('updateHighlightColor', highlightColor.value);
};
</script>
<style scoped>
.iconfont {
  font-family: "iconfont" !important;
  font-size: 30px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  &:hover {
    color: red;
  }
}

.highLight {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: white;
  margin: 10px;
  width: 60px;
  height: 60px;
  border-radius: 10px;
}

.word {
  font-size: 13px;
  margin: 0 5px 5px 5px;

  &:hover {
    color: red;
  }
}

.bodyText {
  margin-top: 20px;
}

.bodyText span {
  cursor: pointer;
}
.controls{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-items: center;
  margin: 0;
}
.el-button{
  margin: 5px;
}
</style>